<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title></title>
	<link rel="stylesheet" href="/Public/layui/css/layui.css">
</head>
<body>

	<blockquote class="layui-elem-quote">
		<button class="layui-btn layui-input-inline" onclick="add()">添加</button>
	</blockquote>
	<fieldset class="layui-elem-field site-demo-button">
		<legend>列表</legend>
		<table id="demo" lay-filter="demo"></table>
	</fieldset>

	

	<script src="/Public/layui/layui.all.js"></script>
	<script type="text/javascript">
		var like = "";


		var object = {};

		function add(){
			ajax('add',{},function(){
				window.location.href = window.location.href;
			})
		}

		table.render({
			elem: '#demo',
			url:"get_list",
			request: {
				pageName: 'page',
				limitName: 'pagesize'
			},
			response: {
				statusName:'isSuccess',
				statusCode:1,
				msgName:'msg',
				countName:'total',
				dataName:'data'
			},
			height: 'full-135',
			cellMinWidth:80,
			page:true,
			limits:[100,200,300,400,500],
			limit:100,
			loading:true,
			id: 'demo',
			initSort: {
				field: 'id',
			},
			text: {
				none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
			},
			cols: [_COLS_],
			
		});

		table.on('edit(demo)', function(obj){
			var value = obj.value //得到修改后的值
			var id = obj.data.id //得到所在行所有键值
			var field = obj.field

			console.log(value);
			console.log(id);
			console.log(field);

			ajaxNotShadow('update',{
				value:value,
				id:id,
				field:field
			})
		});

		table.on('tool(demo)', function(obj){
			if (obj.event == "delete") {
				var index = layer.confirm('删除后无法恢复，确认删除?', {
					icon: 3, 
					title:'温馨提示'
				}, function(index){
					ajax('del',{
						"id":obj.data.id
					},function(res){
						obj.del();
						layer.close(index);
						layer.msg("删除成功！");
					})
					
				});
			}
		});


	</script>
	<script type="text/html" id="barDemo">
		<div class="layui-btn-group">
		    <button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
		 </div>
	</script>

</body>
</html>